//
//  AdminMainVC.swift
//  物料商行
//
//  Created by HaoDong Hong on 2017/9/4.
//  Copyright © 2017年 HaoDong Hong. All rights reserved.
//

import UIKit

class AdminMainVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        if self.revealViewController() != nil {
            //self.revealViewController().delegate = self
            view.addGestureRecognizer(revealViewController().panGestureRecognizer())
            view.addGestureRecognizer(revealViewController().tapGestureRecognizer())
            
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    func prepareMainVC(state: AppState) {
        switch App.state {
        case .AdminState:
            let storyBoard = UIStoryboard(name: "MainStoryboard", bundle: nil)
            let mainVC = storyBoard.instantiateViewController(withIdentifier: "MainViewController")
            let nv = UINavigationController(rootViewController: mainVC)
            self.revealViewController().setFront(nv, animated: true)
        case .ApplyState:
            let navigationVC = UINavigationController(rootViewController: ApplyStoreVC())
            self.revealViewController().setFront(navigationVC, animated: true)
        case .MemberState:
            let navigationVC = UINavigationController(rootViewController: MemberVC())
            self.revealViewController().setFront(navigationVC, animated: true)
        case .none:
            break
        }
    }
}

extension AdminMainVC: LoginDelegate {
    func loginSuccess(from state: AppState) {
        prepareMainVC(state: state)
    }
}

